import { Component } from '@angular/core';
/**
 * @author riverLethe
 * @param info 相关内部涉及参数{timer:计时器}
 * @param interaction 交互相关部分，默认request，response
 * @function $destory 页面销毁函数
 * @function confirm 确认功能函数
 * @constructor 类构造函数
 */
@Component({
    selector: 'default',
    templateUrl: './index.html'
})
export class _DefaultComponent {
    private info = {
        timer: {
            countdown: 0,
            fun: null,
            status: 0 //0：可发送，1：停止，2：转换为发送
        }
    };
    private interaction = {
        request: {
            phoneNum: ''
        }
    };
    private $destory() {
        if (this.info.timer.fun) {
            clearInterval(this.info.timer.fun);
        }
    };
    private confirm() {
        let template = {
            request: {
                phoneNum: this.interaction.request.phoneNum
            }
        }
        if (template.request.phoneNum) {
            switch (this.info.timer.status) {
                case 0:
                    {
                        this.info.timer.status = 1;
                        this.info.timer.countdown = 0;
                        this.info.timer.fun = setInterval(function () {
                            this.data.info.timer.countdown = Number((this.data.info.timer.countdown + 0.1).toFixed(2));
                        }, 100);
                        // ApiStoreResource.Test.SMS(template.request).$promise.then(function(response) {
                        //     this.data.fun.$destory();
                        //     this.data.info.timer.status=2;
                        //     switch (response.statusCode) {
                        //         case CODE.COMMON.SUCCESS:
                        //             {
                        //                 break;
                        //             }
                        //     }
                        // })
                        break;
                    }
                case 1:
                    {
                        this.info.timer.status = 2;
                        this.$destory();
                        break;
                    }
                case 2:
                    {
                        this.info.timer.status = 0;
                        break;
                    }
            }

        }
    };
    constructor() {
        // $scope.$on('$destory', vm.data.fun.$destory);
        // particlesJS.load('particles-js', 'vendor/particles.js/demo/particles.json', function() {
        //     console.log('callback - particles.js config loaded');
        // });
    }

}
